/*
 * VegetableSupplyInfoPanel.cpp
 *
 *  Created on: 09-01-2011
 *      Author: Piotr
 */

#include "customUI/VegetableSupplyInfoPanel.hpp"
#include "pch.hpp"
using namespace boost;
using namespace std;

VegetableSupplyInfoPanel::VegetableSupplyInfoPanel(float parentWidth,
		const VegetableSupply* selected) :
	selected(selected)
{
	createComponents(parentWidth);
}

string VegetableSupplyInfoPanel::getSelectionName() const
{
	return "Vegetable";
}

const VegetableSupply* VegetableSupplyInfoPanel::getSelected() const
{
	return selected;
}

void VegetableSupplyInfoPanel::updateFromSelection()
{
	const float amount = selected->getAmount();
	const RangedValue<float> spoilageTime = selected->getSpoilageTime();
	const float toSpoilage = spoilageTime.getRange().getMaximum() - spoilageTime.getValue();

	amountLabel->setText(lexical_cast<string> (amount));
	toSpoilageLabel->setText(lexical_cast<string> (toSpoilage));
}

void VegetableSupplyInfoPanel::createComponents(float parentWidth)
{
	static const float lineHeight = 20;
	const Dimension halfLineSize(parentWidth / 2.0f, lineHeight);

	float y = 0.0f;
	Label* label = new Label("Amount:   ");
	label->setPosition(Vector(0.0f, y));
	label->setSize(halfLineSize);
	add(label);

	amountLabel = new Label();
	amountLabel->setPosition(Vector(halfLineSize.getWidth(), y));
	amountLabel->setSize(halfLineSize);
	add(amountLabel);

	y += lineHeight;
	label = new Label("To spoilage:   ");
	label->setPosition(Vector(0.0f, y));
	label->setSize(halfLineSize);
	add(label);

	toSpoilageLabel = new Label();
	toSpoilageLabel->setPosition(Vector(halfLineSize.getWidth(), y));
	toSpoilageLabel->setSize(halfLineSize);
	add(toSpoilageLabel);

	setSize(Dimension(parentWidth, y + lineHeight));
}
